﻿<%@ Page Language="C#"  AutoEventWireup="true"  CodeBehind="HospitalManage.aspx.cs"  Inherits="RegisterWeb.Manager.HospitalManager.ManageHospital" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/gray/easyui.css" rel="stylesheet"
        type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-easyui-1.2.6/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>


<script type="text/javascript">

    var url; //提交数据的路径
    var formId; //当天要提交的Form的编号
    var dialogId; //对话框的编号
    
    var successCallback = function (result) {
        alert(result);
        //result为请求处理后的返回值
        var result = eval('(' + result + ')');
        if (result.success) {
            $.messager.show({
                title: 'Success',
                msg: result.msg
            });
            $(dialogId).dialog('close');
            $('#dg').datagrid('reload');
        } else {
            $.messager.show({
                title: 'Error',
                msg: result.msg
            });
        }
    }

    $(function () {
        //预加载编辑框
        $("#addHospital").dialog('refresh');
        $("#editHospitalUser").dialog({

            modal: true,
            "title": "编辑医院信息",
            width: 600,
            height: 500,
            href: 'EditHospital.aspx'
        });
        $("#editHospitalUser").dialog('open').dialog('close');

        $('#dg').datagrid({

            onDblClickRow: function (rowIndex, rowData) {
                $('#editHospitalUser').dialog('open');
                //$('#edit').form('clear');
                //$("#City_ID").combobox('setValue',rowData.City_ID);
                $("#Hospital_Name").val(rowData.Hospital_Name);

                $('#Hospital_Level').combobox('setValue', rowData.Hospital_LevelValue);

                $('#Hospital_Nature').combobox('setValue', rowData.Hospital_NatureValue);

                $('#Hospital_Type').combobox('setValue', rowData.Hospital_TypeValue);
                $("#Hospital_Address").val(rowData.Hospital_Address);
                $("#Hospital_Phone").val(rowData.Hospital_Phone);
                $("#Hospital_Website").val(rowData.Hospital_Website);
                $("#Hospital_Introduce").val(rowData.Hospital_Introduce);
                //$("#Hospital_Logo").val(rowData.Hospital_Logo);
                $("#hidden").val(rowData.Hospital_Logo);
                //$("#Hospital_Recoder").val(rowData.Hospital_LastAmendPerson);
                //      $('#edit').form('clear');
                url = 'ashx/HospitalHandler.ashx?action=edit&id=' + rowData.Hospital_ID;
                formId = "#edit";
                dialogId = "#editHospitalUser";

            }
        });

    });
    //编辑医院部分
    function editHospitalUser() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $("#addHospital").dialog('refresh');
            $('#editHospitalUser').dialog('open');
            // $('#edit').form('clear');
            //$("#City_ID").combobox('setValue', row.City_ID);
            $("#Hospital_Name").val(row.Hospital_Name);

         
            $('#Hospital_Level').combobox('setValue', row.Hospital_LevelValue);
           
            $('#Hospital_Nature').combobox('setValue', row.Hospital_NatureValue);
       
            $('#Hospital_Type').combobox('setValue', row.Hospital_TypeValue);
            $("#Hospital_Address").val(row.Hospital_Address);
            $("#Hospital_Phone").val(row.Hospital_Phone);
            $("#Hospital_Website").val(row.Hospital_Website);
            $("#Hospital_Introduce").val(row.Hospital_Introduce);
           // $("#Hospital_Logo").val(row.Hospital_Logo);
             $("#hidden").val(row.Hospital_Logo);
          
            //$("#Hospital_LastAmendPerson").val(row.Hospital_LastAmendPerson);

            url = 'ashx/HospitalHandler.ashx?action=edit&id=' + row.Hospital_ID;
            formId = "#edit";
            dialogId = "#editHospitalUser";

        }
        else {
            $.messager.alert("提示", "您没有选中任何行！");
        }
    }

    //添加医院部分
    function addHospital() {
        $("#addHospital").dialog('refresh');
        $("#addHospital").dialog({
            modal: true,
            "title": "新建医院",
            width: 600,
            height: 500,
            href: 'AddHospital.aspx'
        });
        $('#addHospital').dialog('open');
        $('#add').form('clear');

        url = 'ashx/HospitalHandler.ashx?action=add';
        formId = "#add";
        dialogId = "#addHospital";
    }

    //添加省区
    function addProvince() {
        $("#addHospital").dialog('refresh');

        $("#addHospital").dialog({
            modal: true,
            "title": "新建省区",
            width: 400,
            height: 240,
            href: 'AddProvince.aspx'
        });
        $('#addHospital').dialog('open');
        $('#addPro').form('clear');

        url = 'ashx/HospitalHandler.ashx?action=addPro';
        formId = "#addPro";
        dialogId = "#addProvince";
    }
    //添加城市
    function addCity() {
        $("#addHospital").dialog('refresh');
        $("#addHospital").dialog({
            modal: true,
            "title": "新建城市",
            width: 400,
            height: 260,
            href: 'AddCity.aspx'
        });
        $('#addHospital').dialog('open');
        $('#addCity').form('clear');
        url = 'ashx/HospitalHandler.ashx?action=addCity';
        formId = "#addCity";
        dialogId = "#addProvince";
    }
    function saveInfo() {
        $(formId).form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: successCallback
        });
    }

    //  删除医院部分
    function deleteHospital() {
       var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('删除提示', '确定要删除' + row.Hospital_Name + '吗', function (r) {
                if (r) {
                    $.post('ashx/HospitalHandler.ashx', { id: row.Hospital_ID, action: 'delete' }, function (data, status) {
                        if (data == "ok") {
                            $('#dg').datagrid('reload');
                            $.messager.show({
                                title: 'Success',
                                msg: '删除成功!'
                            });
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: '删除失败!'
                            });
                        }
                    });
                }
            });
        }
    }
    function checkInstall() {

        var row = $('#dg').datagrid('getSelected');
        $.post('ashx/HospitalHandler.ashx?action=checkInstall', { action: 'checkInstall', id: row.Hospital_ID }, function (data, status) {
            if (data == 'no') {
                $("#addHospital").dialog('refresh');
                $("#addHospital").dialog({
                    modal: true,
                    "title": "新建医院配置",
                    width: 400,
                    height: 330,
                    href: 'AddHospitalInstall.aspx'
                });
                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    $('#addHospital').dialog('open');
                    url = 'ashx/HospitalInstallHandler.ashx?action=addHospitalInstall&id=' + row.Hospital_ID;
                    formId = "#addInstall";
                    dialogId = "#addHospital";

                }
                else {
                    $.messager.alert("提示", "您没有选中任何行！");

                }

            }
            else {
                $.messager.alert("提示", "该医院已配置,可以到配置表中进行查看!", "info"); return;
                }
        });
    }
    //新建医院配置
    /*function addHospitalInstall() {
        if (!checkInstall()) {
            $("#addHospital").dialog('refresh');
            $("#addHospital").dialog({
                modal: true,
                "title": "新建医院配置",
                width: 400,
                height: 330,
                href: 'AddHospitalInstall.aspx'
            });
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $('#addHospital').dialog('open');
                url = 'ashx/HospitalInstallHandler.ashx?action=addHospitalInstall&id=' + row.Hospital_ID;
                formId = "#addInstall";
                dialogId = "#addHospital";

            }
            else {
                $.messager.alert("提示", "您没有选中任何行！");

            }
        }
        else {
            $.messager.show({title:"提示", msg:'该医院已配置,可以到配置表中进行查看.'});
        }
        }
       */
      
    function warn() {
        $("#warn").text("例如:http://www.baidu.com");
    
    }
    function hide() {
        $("#warn").text("");
    }
</script>

</head>
<body>
    <form id="form1" >
    <div region="center" title="医院信息管理" >
<table id="dg" title="医院信息管理" class="easyui-datagrid" style="width:850px;height:550px"
			url="ashx/HospitalHandler.ashx?action=get"
			toolbar="#toolbar" pagination="true"
			rownumbers="true" fitColumns="true" singleSelect="true" 
            pageSize="20"
            >
		<thead>
			<tr>
			<th field="Province_ID" width="50">

所在省</th>
				<th field="City_ID" width="50">所

在市</th>
				<th field="Hospital_Name" 

width="50">医院名称</th>
				<th field="Hospital_Level" 

width="50">等级</th>
  <th field="Hospital_LevelValue" hidden="true"> 等级值</th>
                <th field="Hospital_Nature" width="50">性质</th>
                 <th field="Hospital_Type" width="50">类别</th>
                 <th field="Hospital_Address" width="50">地址

</th>
                 <th field="Hospital_Website" width="50">网址

</th>
                 <th field="Hospital_Phone" width="50">联系电话

</th>
                 <th idField="Hospital_ID" width="10"  hidden="true" >医院ID</th>
                 <th field="Hospital_Introduce" width="10" hidden="true">医院介绍

</th>
 <th field="Hospital_Logo" width="10" hidden="true">图片路径

</th>
<th field="Hospital_Recoder" width="10" hidden="true">上传者

</th>
			</tr>
		</thead>
	</table>

    <div id="toolbar" style="padding:5px;height:auto">
					<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addHospital()">添加医院</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editHospitalUser()">编辑医院</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteHospital()">删除医院</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addProvince()">添加省区</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addCity()">添加城市</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="checkInstall()">医院配置</a>
    </div>


			<div id="addHospital" class="easyui-dialog" closed="true" buttons="#addHospital-buttons" style="padding:10px 20px">
        	</div>
			<div id="addHospital-buttons">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveInfo()">保存</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick='$("#addHospital").dialog("close");'>关闭</a>
			</div>

            <div id="editHospitalUser" class="easyui-dialog" closed="true" buttons="#editHospitalUser-buttons" style="padding:10px 20px">
        	</div>
            <div id="editHospitalUser-buttons">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok"  onclick="saveInfo()">保存</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick='$("#editHospitalUser").dialog("close");'>关闭</a>
			</div>

    </div>
    </form>
</body>
</html>
